<template>
  	<basic-container>
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
   <el-form-item label="客户账号" prop="accountNo">
     <el-input v-model="agreementNo" placeholder="" readonly></el-input>
   </el-form-item>
   <el-form-item label="客户简称" prop="customerjcName">
     <el-input v-model="customerJcName" placeholder="" readonly></el-input>
   </el-form-item>
   <el-form-item label="支付方式" prop="nowType">
     <el-select v-model="dataForm.nowType" placeholder="请选择">
          <el-option
            v-for="item in zftypelist"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>

   </el-form-item>
    <el-form-item label="发生时间" prop="creatTime">
      <el-date-picker
            v-model="dataForm.creatTime"
            type="datetime"
           value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择日期" readonly>
            </el-date-picker>
    </el-form-item>
    <el-form-item label="金额" prop="payPrice">
      <el-input type="number" v-model="dataForm.payPrice" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="单据号" prop="no">
      <el-input v-model="no" placeholder="单据号"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remarks">
      <el-input v-model="dataForm.remarks" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="cancelReturn()">取消</el-button>
      <el-button type="primary" @click="save()">确定</el-button>
    </span>
  </basic-container>
</template>

<script>
  export default {
    name:'yskaddd',
    props: {
    	cancelReturn: {
    		type: Function
    	},
    	id: {
    		type: String
    	},
    	agreementNo: {
    		type: String
    	},
    	customerJcName: {
    		type: String
    	},
    	mainid: {
    		type: String
    	},
      sktype:{
        type:String
      },
      customerName:{
         type:String
      }
    },
    data () {
      return {
        visible: false,
        zftypelist:[],
        no:'',
        dataForm: {
          submitType:'1',
          creatTime:  new Date(),
          banksNumber: '',
          customerName: '',
          nowType: '',
          type: '',
          payPrice: '',
          registrationNo: '',
          remarks: '',
          createUserId: '',
          updateData: '',
          agreementId:'',
          collectionNo:'',
          payType:'',
          refundNo:''
        },
        dataRule: {
          creatTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          nowType: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],

          payPrice: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],

        }
      }
    },
   created() {
     this.getAggreementList();
   			console.log(this.agreementNo);
   			console.log(this.customerJcName);
   			if ("" != this.id && this.id != undefined) {
   				this.getByid(this.id);
   			}
   		},
   		methods: {

        //获取状态分组
        getAggreementList() {
          this.$http({
            url: this.$http.adornUrl('/hotel/thotelfloorroompaytype/list'),
            method: 'get',
            params: this.$http.adornParams({
              page: 1,
              limit: 999,
			  state: 1
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              
           this.zftypelist =data.page.list;

            } else {
                this.zftypelist =[];
            }
          });
        },
   			getByid(id) {
   				this.$http({
   					url: this.$http.adornUrl(
   						`/hotel/tagreementyskpayment/info/` + id
   					),
   					method: "post",
   				}).then(({
   					data
   				}) => {
   					this.dataForm = data.tAgreementYskpayment;
   				});
   			},

   			// 表单提交
   			save() {
         var year =this.dataForm.creatTime.getFullYear();//获取完整的年份(4位,1970-????)
                         var month = this.dataForm.creatTime.getMonth() + 1;//获取当前月份(0-11,0代表1月)
                         var day = this.dataForm.creatTime.getDate();//获取当前日(1-31)
                         if (month < 10) {
                              month ="0" + month;
                          }
                         if (day < 10) {
                              day ="0" + day;
                          }
         var h= this.dataForm.creatTime.getHours();       // 获取当前小时数(0-23)
          var s=this.dataForm.creatTime.getMinutes();     // 获取当前分钟数(0-59)
          var a=this.dataForm.creatTime.getSeconds();
           if (h < 10) {
                               h ="0" + h;
                           }
                          if (s < 10) {
                               s ="0" + s;
                           }
           if (a < 10) {
                               a ="0" + a;
                           }
                        
          var dateString = year +"-" + month + "-" + day  +"  "+h+":"+s+":"+a;
          this.dataForm.creatTime=dateString;
          if(this.sktype=='0'){
            this.dataForm.collectionNo=this.no;
            this.dataForm.payType='0';
          }
          if(this.sktype=='5'){
            this.dataForm.refundNo=this.no;
            this.dataForm.payType='5';
          }
          this.dataForm.agreementId = this.mainid;
          this.dataForm.customerName = this.customerName;
   				this.dataForm.banksNumber = this.agreementNo;
   				this.$refs["dataForm"].validate(valid => {
   					if (valid) {
   						this.$http({
   							url: this.$http.adornUrl(
   								`/hotel/thotelfloorroomcheckinaccounting/${!this.id ? "saveAgreement" : "update"}`
   							),
   							method: "post",
   							data: this.dataForm
   						}).then(({
   							data
   						}) => {
   							if (data && data.code === 0) {
   								this.$message({
   									message: "操作成功",
   									type: "success",
   									duration: 1500,
   									onClose: () => {
   										this.cancelReturn();
   									}
   								});
   							} else {
   								this.$message.error(data.msg);
   							}
   						});
   					}
   				});
   			}
   		}

   	}
   </script>
</script>
